<?php

require_once 'smarty_lib/Smarty.class.php';
require_once 'lib/DBClass.php';
require_once 'lib/Account.php';
require_once 'lib/Tag.php';

$smarty = new Smarty();
$acc = new Account();
$tag = new Tag();

$smarty->template_dir = 'template/';
$smarty->compile_dir = 'template_c/';

if(!$acc->validate_cookie()){
	$smarty->assign('error','Anda tidak mempunyai akses untuk membuka halaman ini');
	$smarty->display('fuf-login.html');
}else{
	
	$smarty->assign('cookie', $acc->get_cookie());
	$smarty->assign('page','tag.html');
	$smarty->assign('desc','Kamu bisa merubah tag artikel yang sudah ada atau menambahnya dengan yang baru.');
	$smarty->assign('title','Tag Artikel');

	$data = $tag->get_all_tag();
	$smarty->assign('tag', $data);

	if (@$_GET['action'] == 'save') {
		$form = $_POST;
		$add = $tag->addtag($form);
	}

	if (@$_GET['action'] == 'edit') {
		$data = $_POST;
		$edit = $tag->editTag($data);
	}

	if (@$_GET['action'] == 'delete') {
		$id = $_GET['id'];
		$delete = $tag->deleteTag($id);
	}

	if(@$_GET['action'] == 'getajax'){
		$id = $_GET['id_tag'];
		$tag = $tag->getTag($id);
		echo json_encode($tag);
	}

	if(@$_GET['action'] != 'getajax'){
		$smarty->display('dashboard.html');
	}
}